// VBConversions Note: VB project level imports
using System.Data;
using DevExpress.XtraEditors.Controls;
using System.Diagnostics;
using System.Xml.Linq;
using DevExpress.XtraEditors.Repository;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.VisualBasic;
using System.Configuration;
using System.Collections;
using DevExpress.XtraEditors;
using System.Data.Sql;
using Microsoft.SqlServer;
using System.Windows.Forms;
using System;
using DevExpress.XtraReports;
using Microsoft.SqlServer.Management.Smo;
using DevExpress;
using System.Linq;
using System.IO;
// End of VB project level imports


namespace SCIEF.SysBFW.CommonExt
{
	public class MetaApplication : IDisposable
	{
		
		private bool disposedValue = false; // To detect redundant calls
		private MetaApplicationOptions _metaApplicationOptions = new MetaApplicationOptions();
		private MetaQuery mq;
		
		public Guid ApplicationID {get; set;}
		public string AppName {get; set;}
		public bool SystemRecord {get; set;}
		
		public MetaApplicationOptions MetaApplicationOptions
		{
			get
			{
				return _metaApplicationOptions;
			}
		}
		/// <summary>
		/// Application class that contains, all the value and the description of the ApplicationOption.
		/// </summary>
		/// <param name="appName"></param>
		/// <remarks>Populate by the MetaCommand Metalists</remarks>
		public MetaApplication(string appName)
		{
			this.AppName = appName;
			this.FillMetaApplication();
			this.FillMetaApplicationOption();
		}
		
		public void FillMetaApplication()
		{
			mq = MetaQuery.GetMetaQueryByName("MetaApplications");
			mq.SQLWhere = string.Format("AppName = \'{0}\'", this.AppName);
			mq.FillResultQuery();
			foreach (DataRow row in mq.ResultQuery.Rows)
			{
				this.ApplicationID = (Guid) (row["ApplicationID"]);
				this.AppName = row["AppName"].ToString();
				this.SystemRecord = System.Convert.ToBoolean(row["SystemRecord"]);
			}
		}
		
		public void FillMetaApplicationOption()
		{
			MetaApplicationOption mao = default(MetaApplicationOption);
			//Dim gid As Guid
			
			mq = MetaQuery.GetMetaQueryByName("MetaApplicationOptions");
			mq.SQLWhere = string.Format("ApplicationID_FK = \'{0}\'", this.ApplicationID);
			mq.FillResultQuery();
			foreach (DataRow row in mq.ResultQuery.Rows)
			{
				mao = new MetaApplicationOption();
				
				mao.AppOptionId = (Guid) (row["AppOptionId"]);
				mao.ApplicationID_FK = (Guid) (row["ApplicationID_FK"]);
				mao.OptionDescr = row["OptionDescr"].ToString();
				mao.OptionName = row["OptionName"].ToString();
				mao.DfltOptionValue = row["DfltOptionValue"].ToString();
				mao.Notes = row["Notes"].ToString();
				mao.Overwritable = System.Convert.ToBoolean(row["Overwritable"]);
				mao.Readonly = System.Convert.ToBoolean(row["Readonly"]);
				mao.SystemRecord = System.Convert.ToBoolean(row["SystemRecord"]);
				
				//gid = New Guid(row("ListValueID").ToString)
				if (!this._metaApplicationOptions.ContainsKey(mao.OptionName))
				{
					this._metaApplicationOptions.Add(mao.OptionName, mao);
				}
			}
			
		}
		
		
		// IDisposable
		protected virtual void Dispose(bool disposing)
		{
			if (!this.disposedValue)
			{
				if (disposing)
				{
					// TODO: free other state (managed objects).
					_metaApplicationOptions = null;
					mq = null;
				}
				// TODO: free your own state (unmanaged objects).
				// TODO: set large fields to null.
			}
			this.disposedValue = true;
		}
		
#region  IDisposable Support
		// This code added by Visual Basic to correctly implement the disposable pattern.
		public void Dispose()
		{
			// Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
			Dispose(true);
			GC.SuppressFinalize(this);
		}
#endregion
		
	}
	
	public class MetaApplicationOption
	{
		
		public Guid AppOptionId {get; set;}
		public Guid ApplicationID_FK {get; set;}
		public string OptionName {get; set;}
		public string OptionDescr {get; set;}
		public string DfltOptionValue {get; set;}
		public string Notes {get; set;}
		public bool Overwritable {get; set;}
		public bool Readonly {get; set;}
		public bool SystemRecord {get; set;}
		
		public MetaApplicationOption()
		{
		}
		
		
	}
	
	public class MetaApplicationOptions : System.Collections.Generic.Dictionary<string, MetaApplicationOption>
	{
		
	}
	
	
}
